package com.uvlab.sitespot.io;

import com.uvlab.sitespot.service.JxAppService;
import com.uvlab.sitespot.service.fdb.JxAppFdbService;
import com.uvlab.sitespot.service.node.JxNode;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * Created by Jys on 2016/5/14 0014.
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/rest/fdb")
public class JxFdbController {

    @Resource(name = "svc")
    private JxAppService svc;
    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "获得节点", httpMethod = "GET", response = JxNode.class, notes = "get nodes")
    public LinkedHashMap get() {

        return svc.getAppFdbService().getNodeList();
    }


    @RequestMapping(method = RequestMethod.GET,value = "/filter")
    public LinkedHashMap getNodes(@RequestParam(value = "user") String user,
                                  @RequestParam(value = "begtime") String begtime,
                                  @RequestParam(value = "endtime") String endtime){
        return svc.getAppFdbService().getNodeList(user, begtime, endtime);

    }

    @RequestMapping(method = RequestMethod.POST)
    /*public String add(@RequestParam("name")String name,
                    @RequestParam("user")String user,
                    @RequestParam("updtime")String updtime) {
        return svc.getAppFdbService().add(name, user, updtime);*/
    public String add(@RequestBody JxNode node) {
        return svc.getAppFdbService().add(node);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public  JxNode getById(@PathVariable(value="id") String id){
        return  svc.getAppFdbService().getById(id);
    }
    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public  JxNode updateById(@RequestBody JxNode node){
        return  svc.getAppFdbService().updateById(node);
    }

    @RequestMapping(method = RequestMethod.DELETE,value = "/{id}")
    public void deleteById(@PathVariable(value="id")String id){
        svc.getAppFdbService().deleteById(id);
    }

    @RequestMapping(method = RequestMethod.GET,value = "/{id}/children")
    public LinkedHashMap getChildren(@PathVariable(value = "id") String id){
        return svc.getAppFdbService().getChildren(id);
    }

    @RequestMapping(value = "/{id}/children",method = RequestMethod.POST)
    public String addById(@RequestBody JxNode node,
                          @PathVariable(value="id") String id) {
        return svc.getAppFdbService().addById(node, id);
    }

    @RequestMapping(value = "/{id}/parents",method = RequestMethod.GET)
    public LinkedHashMap<String,JxNode> getParents(){
        return null;
    }


}
